package common.entities.persistent;

import common.entities.abst.AbstPersonEntity;
import common.entities.enums.SEX;


/**
 * @author Yoyo
 *
 */
public class Actor extends AbstPersonEntity {
	
	private SEX sex;
	
	/**
	 * This constructor will be used for entities that are fetched from the DB
	 * 
	 * @param id
	 * @param firstName
	 * @param lastName
	 * @param sex
	 */
	public Actor(int id, String firstName, String lastName, SEX sex) {
		super(id, firstName, lastName);
		
		this.sex = sex;
	}

	
	/**
	 * This constructor will be used for new entities (i.e still weren't saved into DB)
	 * 
	 * @param firstName
	 * @param lastName
	 * @param sex
	 * @param occurennces
	 */
	public Actor(String firstName, String lastName, SEX sex) {
		super(firstName, lastName);
		
		this.sex = sex;
	}

	public Actor() {
		super();
	}
	
	
	/**
	 * @return the sex
	 */
	public SEX getSex() {
		return sex;
	}

	/**
	 * @param sex the sex to set
	 */
	public void setSex(SEX sex) {
		this.sex = sex;
	}
	
	/**
	 * @param sex the sex to set
	 */
	public void setSex(int sex) {
		if (sex == SEX.MALE.getValue())
			this.sex = SEX.MALE;
		else
			this.sex = SEX.FEMALE;
			
	}

	
	/**
	 * Is used to validate the sex according to the DB constraints
	 * 
	 * @param sex
	 * @throws IllegalArgumentException
	 */
	public static void validateSex(SEX sex) throws IllegalArgumentException{
		if(sex == null)
			throw new IllegalArgumentException("Sex cannot be null");
	}

	
	@Override
	public String toString() {
		return "Actor: " + this.getFirstName() + ", " + this.getLastNameWithPersonNumber() + "  (" + this.getSex() + ")";
	}
	
	
	@Override
	public boolean equals(Object obj) {
		Actor cmpActor = (Actor) obj;
		
		return ( super.equals(obj) && (this.getSex() == cmpActor.getSex()) );
	}
	

}
